unit Thrad_ImptSORT;

interface

uses
  Classes,SysUtils,Class_KzThrad,Class_SORT,Uni,UniConnct;

type
  TThradImptSORT = class(TKzThrad)
  public
    FListSORT:TCollection; //&list of &tsort
    FSaveTabl:string;
  protected
    procedure Execute; override;
  end;

const
  CONST_MARK_ZCGL='ZCGL';
  
implementation

uses
  ActiveX;


procedure TThradImptSORT.Execute;
var
  I:Integer;
  Sort:TSORT;
  UniConnct:TUniConnection;
begin
  CoInitialize(nil);

  try
    UniConnct:=UniConnctEx.GetConnection(CONST_MARK_ZCGL);
    try
      UniConnct.StartTransaction;
      //-<
      UniConnct.ExecSQL('DELETE FROM TBL_SORT_2010');
      GetMaxProgress(FListSORT.Count);
      for I:=0 to FListSORT.Count-1 do
      begin
        Sort:=TSORT(FListSORT.Items[I]);
        if Sort=nil then Continue;

        Sort.SORTIDEX:=I+1;
        Sort.TablNam :=FSaveTabl;
        Sort.PrepareYSDM('1222');
        Sort.InsertDB(UniConnct);

        GetOneProgress(I+1);
      end;
      //->
      UniConnct.Commit;
    except
      on E:Exception do
      begin
        UniConnct.Rollback;
        raise Exception.Create(E.Message);
      end;
    end;
  finally
    FreeAndNil(UniConnct);
  end;
  
  CoUninitialize;
end;

end.
